package com.ruoyi.edh.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhSupplier;
import com.ruoyi.edh.service.IEdhSupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-供应商Controller
 *
 * @author xxx
 * @date 2020-09-03
 */
@RestController
@RequestMapping("/edh/supplier")
@Api(description = "易订货-供应商")
public class EdhSupplierController extends BaseController {
    @Autowired
    private IEdhSupplierService edhSupplierService;

    /**
     * 查询易订货-供应商列表
     */
    @PreAuthorize("@ss.hasPermi('edh:supplier:list')")
    @GetMapping("/list")
    @ApiOperation("易订货-供应商列表")
    public TableDataInfo list(EdhSupplier edhSupplier) {
        startPage();
        List<EdhSupplier> list = edhSupplierService.selectEdhSupplierList(edhSupplier);
        return getDataTable(list);
    }

    /**
     * 导出易订货-供应商列表
     */
    @PreAuthorize("@ss.hasPermi('edh:supplier:export')")
    @Log(title = "易订货-供应商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-供应商列表")
    public AjaxResult export(EdhSupplier edhSupplier) {
        List<EdhSupplier> list = edhSupplierService.selectEdhSupplierList(edhSupplier);
        ExcelUtil<EdhSupplier> util = new ExcelUtil<EdhSupplier>(EdhSupplier.class);
        return util.exportExcel(list, "supplier");
    }

    /**
     * 获取易订货-供应商详细信息
     */
    @PreAuthorize("@ss.hasPermi('edh:supplier:query')")
    @GetMapping
    @ApiOperation("获取易订货-供应商详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhSupplierService.selectEdhSupplierById(id));
    }

    /**
     * 新增易订货-供应商
     */
    @PreAuthorize("@ss.hasPermi('edh:supplier:add')")
    @Log(title = "易订货-供应商", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-供应商")
    public AjaxResult add(@RequestBody EdhSupplier edhSupplier) {
        return toAjax(edhSupplierService.insertEdhSupplier(edhSupplier));
    }

    /**
     * 修改易订货-供应商
     */
    @PreAuthorize("@ss.hasPermi('edh:supplier:edit')")
    @Log(title = "易订货-供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-供应商")
    public AjaxResult edit(@RequestBody EdhSupplier edhSupplier) {
        return toAjax(edhSupplierService.updateEdhSupplier(edhSupplier));
    }

    /**
     * 删除易订货-供应商
     */
    @PreAuthorize("@ss.hasPermi('edh:supplier:remove')")
    @Log(title = "易订货-供应商", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-供应商")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhSupplierService.deleteEdhSupplierByIds(ids));
    }
}
